from pandac.PandaModules import *

loadPrcFile('Config.prc')

import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor
from direct.interval.MetaInterval import *
import math

import maultasche as mt

#for the events
from direct.showbase import DirectObject

from Picker import Picker
from pcamera import CameraMover

mycam = CameraMover()
base.disableMouse()

def prepareMap():
    # Create Ambient Light
    ambientLight = AmbientLight( 'ambientLight' )
    ambientLight.setColor( Vec4( 0.3, 0.3, 0.3, 1 ) )
    ambientLightNP = render.attachNewNode( ambientLight.upcastToPandaNode() )
    render.setLight(ambientLightNP)
    
    # Directional light 01
    directionalLight = DirectionalLight( "directionalLight" )
    directionalLight.setColor( Vec4( 1.0, 1.0, 1.0, 1 ) )
    directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode() )
    # This light is facing backwards, towards the camera.
    directionalLightNP.setHpr(225, -40, 0)
    render.setLight(directionalLightNP)
    
    # load terrain
    # just a huge cube for now, perhaps with texture?
    PLAYFIELD_X = 256
    PLAYFIELD_Y = 256
    terrain = loader.loadModel('cube')
    terrain.getChild(0).setName('terrain')
    terrain.setPos(0,0,-0.5)
    terrain.setScale(PLAYFIELD_X,PLAYFIELD_Y,0.01)
    terrain.setColor(0.4, 0.4, 0.4, 1.0)
    wireframetex = loader.loadTexture('wireframe_64.png')
    terrain.setTexture(wireframetex)    
    
    terrain.reparentTo(render)

def createCompany(pos, playa, front, flank, officer):
    newCompany = mt.Company(256, playa, front, flank, officer)
    mousePicker.makePickable(newCompany)
    newCompany.setPos(pos)
    return newCompany


welt = mt.WorldMgr()
prepareMap()

fooPlayer = mt.Player('Foobarius', 'Foobars', 1, (0,0,1), (0.3,0.3,0.3))
barPlayer = mt.Player('Barba\'az', 'Barbazes', 2, (1,0,0), (0.3,0.3,0.3))

fooCity = mt.City(0, fooPlayer)
fooCity.setPos(20,20,0)


fooCompany = welt.createCompany((0,0), fooPlayer, "footman", "footman", "legionary")
barCompany = welt.createCompany((10,0), fooPlayer, "footman", "footman", "legionary")
badCompany = welt.createCompany((-10,10), barPlayer, "footman", "footman", "legionary")

mousePicker=Picker()
mousePicker.companies = welt.companies
mousePicker.cities = [fooCity]

for c in welt.companies:
    mousePicker.makePickable(c)

##foofont = loader.loadFont('cmr12.egg')
##text = TextNode('node name')
##text.setFont(foofont)
##text.setText("foobar!")
##textNodePath.setScale(0.07)

from direct.gui.OnscreenText import OnscreenText
textObject = OnscreenText(text = fooPlayer.name,
    pos = (-0.9, 0.8), scale = 0.07, bg=(0.3,0.3,0.4,0.8))

run()
